<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <!-- div id 为 app 挂载点 -->
     <div id="app">
        <h2>组件A:向总线bus上报事件</h2>
        <my-component-a></my-component-a>
        <h2>组件B:向总线bus上报事件</h2>
        <my-component-b></my-component-b>

        <template>
            <div>
                
                
            </div>
        </template>

     </div>
    
    
     <!-- 使用 javascript 脚本 -->
      <script type="text/javascript">

         var bus = new Vue();

         Vue.component('my-component-a', { 
         template:`<div>
            <p>组件A</p>
            <hr>
            <button v-on:click="doclick">{{counter}}</button>
        </div>`,

        data() {
            return {
                counter: 0
            }
        },
        methods: {
            doClick(){
                this.counter++;
                bus.$emit('btn-click',this.counter)
            }
        },
});

Vue.component('my-component-b', { 
         template:`<div>
            <p>组件B</p>
            <hr>
            计数器:{{ counter }}
            <hr>
        </div>`,

        data() {
            return {
                counter: 0
            }
        },
        created() {
            bus.$on('btn-click',(counter) =>{
                this.counter = counter;
            })
        },
        methods: {
           
               
            }
        
    })

    var app = new Vue({
        el:'#app',
        data:{
            total:0
        }
    })

      </script>
</body>
</html>